var g_hero = null;
var Hero = Tank.extend({
    ///////////////////////////////////////////////////////////
    ctor : function(filename,hp,speed){
        this._super(filename,hp,speed);
        g_hero = this;
    },
    onEnter:function () {
        this._super();
    },
    onExit : function(){
        this._super();
    },
    ///////////////////////////////////////////////////////
    dead : function(){
        PlayHeroEffect(0,this.getPosition());
        this._life = false;
        this.setVisible(false);
    },
    ///////////////////////////////////////////////////////
    toUp : function(){
        // alter skins
        var filename = MainResource( "hero00.png" );
        var frame = new cc.SpriteFrame( filename,cc.rect(0,0,80,80) );
        this.setSpriteFrame(frame);
    },
    toRight : function(){
        var filename = MainResource( "hero02.png" );
        var frame = new cc.SpriteFrame( filename,cc.rect(0,0,80,80) );
        this.setSpriteFrame(frame);
        this.setScaleX(1);
    },
    toDown : function(){
        var filename = MainResource( "hero01.png" );
        var frame = new cc.SpriteFrame( filename,cc.rect(0,0,80,80) );
        this.setSpriteFrame(frame);
    },
    toLeft : function(){
        this.toRight();
        this.setScaleX(-1);
    },
    ////////////////////////////////////////////////////
    newBullet : function(){
        cc.log("new a hero bullet");
        var name = MainResource( "hB00.png" );
        var bullet = new Bullet( name,5,500);
        bullet.setType(0);
        // add bullet to scene
        AddHBullet(bullet);
        return bullet;
    },
    ////////////////////// firing //////////////////////
    firing : function(){
        if(this._life){
            var bullet = GetHBulletFromBuffer();
            if(null==bullet){
                bullet = this.newBullet();
            }
            bullet.revive(this);
            var filename = AudioResource("aFire.mp3");
            cc.audioEngine.playEffect(filename);
        }
    }
});
GetHero=function(){
    if(g_hero) {
        cc.log("get  g_hero");
        return g_hero;
    }else{
        cc.log("g_hero invalid");
        return null;
    }
}
